
#include "StateManager.h"


StateManager::StateManager()
{
	SDLBase::inicializaSDL();
	frameStart = SDL_GetTicks();
	estadoAtual = new stateGame();
	estadoAtual->load();
	inputManager->Update();
	estadoAtual->update(dt);
}


StateManager::~StateManager()
{
	estadoAtual->unload();
	delete(estadoAtual);
	SDL_Quit();
	TTF_Quit();
}


void StateManager::run()
{
	bool quit = false;

	while(!quit)
	{

		/* Calculo de Timer e dt */
		frameEnd = frameStart;
		frameStart = SDL_GetTicks();
		dt = frameStart - frameEnd;
//		cout << dt << "ms "<< endl;
//		cout << endl;


		/* Delay */
		if (33 - dt > 0)
			SDL_Delay(33 - dt);

		/* Captura de Input */
		inputManager->Update();

		/* STATE MANAGER */
		estadoAtual->update(dt);

		/* Atualizacao dos objetos na tela */
		SDLBase::atualizarTela();
	}
}


